// export const baseUrl = 'https://jw.xzsw2021.com/api/' //需要暴露出去！
export const baseUrl = 'http://192.168.2.140/api/'
// export const baseUrl = 'http://192.168.2.211/api/'
// export const baseUrl = 'http://www.jw.com/api/'


const request = (url = '', date = {}, type = 'POST') => {
	return new Promise((resolve, reject) => {
		uni.request({
			method: type,
			url: baseUrl + url,
			data: date,
			header:{}
		}).then((response) => {
			let [error, res] = response;
			if (res.data.status == 410000 || res.data.status == 410001 || res.data.status ==
				410002 || res.data.status == 40000 || res.data.message == '请登录') {
				uni.showToast({
					title: "登录失效",
					icon: "none"
				})
				reject(res.data)
			}
			if (res.data.status == 400) {
				if (url == 'v2/order/check' && res.data.message == '数据无效') {

				} else {
					uni.showToast({
						title: res.data.message || res.message,
						icon: "none"
					})
					reject(res.data)
				}
			}
			resolve(res.data);
		}).catch(error => {
			let [err, res] = error;
			console.log(err)
			reject(err)
		});
	})
}


['options', 'get', 'post', 'put', 'head', 'delete', 'trace', 'connect'].forEach((method) => {
	request[method] = (api, data) => request(api, data, method)
});


export default request
